package cpr.data;

import java.util.Iterator;

import cpr.Rule;
import cpr.Utils;

public class HLIterator implements Iterator {
        private int currScore;
        private HLVector startVector;
        private final int maxScore = Rule.HL_SCORE[Rule.HL_DUCPR_PRODM]*2;
        private HLVector nextValue;
        private void computeNextValue() {
            nextValue = null;
            while ((currScore<maxScore)&&(nextValue==null)) {
                int[] decay =Utils.decayScore(currScore, Rule.HL_SCORE);
                if (decay!=null) {
                	if (isBiggerThanStart(decay)) {
                	     nextValue = new HLVector(decay);
                	}
                }
                currScore++;
            }
            if (startVector==null) {
            	startVector = nextValue;
            }
        }
        private boolean isBiggerThanStart(int[] decay) {
        	if (startVector==null) return true;
        	for (int i=0;i<decay.length;i++) {
        		if (decay[i]<startVector.values[i]) {
        			return false;
        		}
        			
        	}
        	return true;
        }
        public HLIterator(int start) {
            currScore = start;
            computeNextValue();
        }
        public boolean hasNext() {
            return (nextValue!=null);
        }

        public Object next() {
            HLVector res = nextValue;
            computeNextValue();
            return res;
        }

        public void remove() {
        }
        
    }

